﻿var feedbacklist = {
    formDefine: {
        labelWidth: 50,
        fields: [
                    { display: lang.information_type, name: "feedbacktype", type: "select", labelWidth: 90 },
                    { display: lang.state, name: "state", type: "select", labelWidth: 90 },
                    { display: lang.Start_date, name: "begindate", type: "date", labelWidth: 80 },
        //
                    {display: lang.The_deadline, name: "enddate", type: "date", labelWidth: 80 },
                    { display: lang.account, name: "userid", type: "text" },
                    { display: lang.Query, name: "search", type: "button", click: function () { feedbacklist.search(); } }
                ],
        fieldsInit: function () {
            feedbackdict();
            statedict();
        }
    },
    gridDefine: {
        columns: [
         { display: lang.date, name: 'CREATEDATE', minWidth: 120, align: 'center' },
          { display: lang.account, name: 'USER_ID', minWidth: 80 },
            { display: lang.user_name, name: 'USER_NAME', minWidth: 90 },


            { display: lang.title, name: 'FEEDBACK_TITLE', minWidth: 100, sortable: true },
            { display: lang.annex, name: 'FEEDBACK_ATTACHNAME', minWidth: 200, render: linkattach },
            { display: lang.content, name: 'FEEDBACK_CONTENT', minWidth: 400 },
            { display: lang.state, name: 'itemname', minWidth: 100, render: LinkAuthority, align: 'center' },
            { display: lang.operation, name: 'FEEDBACK_ID', minWidth: 90, render: LinkOP, align: 'center' }
        ],
        url: App_Config.TadongUrl + "/AjaxMappingHandler.aspx",
        urlType: "QueryFeedbackInfoList"
    },
    init: function () {
        jsPageRender(this, true);
        getAuthority();
    },
    search: function () {
        jsPageSearch(this);
    }
};

var authorityArr = [];
function getAuthority() {
    $.ajaxHandler({
        url: App_Config.TadongUrl + "/AjaxMappingHandler.aspx",
        urlType: "QueryDictItemList2",
        model: function () { return 1001; },
        success: function (data) {
            if (data) {
                authorityArr = data;
            }
        }
    });
}

function LinkOP(value, row, index) {
    var _str = 'FEEDBACK_ID=' + row.FEEDBACK_ID;

    return '<span style="align:center;"><a href="javascript:void(0)" onclick="deleteuser(\'' + row.FEEDBACK_ID + '\',\'' + row.FEEDBACK_TITLE + '\');">'+lang.delete_+'</a></span>';
}
function LinkAuthority(value, row, index) {
    var str = row.itemname || '';
    return str + '<span id="op_' + row.FEEDBACK_ID + '"><a href="javascript:void(0)" onclick="handlerlevel(\'' + row.FEEDBACK_ID + '\',\'' + row.itemvalue + '\');">[' + lang.set + ']</a></span>';
}

function handlerlevel(id, value) {
    var html = [];
    html.push('<select>');

//    html.push('<option value="1">已更新</option>');
//    html.push('<option value="2">未更新</option>')
//    html.push('<option value="3">正在更新</option>')
    for (var i = 0; i < authorityArr.length; i++) {
        if (authorityArr[i].ITEMVALUE == 100) continue;
        html.push('<option value="' + authorityArr[i].ITEMVALUE + '">' + authorityArr[i].ITEMNAME + '</option>');
    }
   
    html.push('<select>');
    html.push('<input type="button" value=' + lang.save + ' onclick="saveAuthority(' + id + ')" >');
    $('#op_' + id).html(html.join(''));
}

function saveAuthority(id) {
    $.ajaxHandler({
        url: App_Config.TadongUrl + "/AjaxMappingHandler.aspx",
        urlType: "SaveFeadbackAuthority",
        model: function () { return $.toJSON({ tableid: id, authority: $('#op_' + id + ' select').val() }); },
        success: function (data) {
            if (data) {
                //structtbmanage.search();
            }
        }
    });
}

//#region 删除
function deleteuser(FEEDBACK_ID, FEEDBACK_TITLE) {
    $.extend($.messager.defaults, {
        ok: lang.ok,
        cancel: lang.cancel
    });
    $.confirm(lang.Sure_to_delete_feedback + "[" + FEEDBACK_TITLE + "]", lang.Delete_feedback, function (b) {
        if (b) {
            $.ajaxHandler({
                url: App_Config.TadongUrl + "/AjaxMappingHandler.aspx",
                urlType: "DelFeedBack",
                model: function () { return $.toJSON({ 'FEEDBACK_ID': FEEDBACK_ID }); },
                success: function (data) {
                    $.alert(lang.Successfully_deleted , null, function () {

                    feedbacklist.search(); });
                }
            });
        }
    });
}


function feedbackdict() {
    $.ajaxHandler({
        url: App_Config.TadongUrl + "/AjaxMappingHandler.aspx",
        urlType: "QueryDictItemList2",
        model: function () { return Sys_Config.FeedbackDict; },
        success: function (data) {
            if (data && data.length > 0) {
                $("#formidfeedbacktype").combobox({ valueField: 'ITEMVALUE', textField: 'ITEMNAME' });
                $("#formidfeedbacktype").combobox('loadData', data);

            }
        }
    });
}
function statedict() {
    $.ajaxHandler({
        url: App_Config.TadongUrl + "/AjaxMappingHandler.aspx",
        urlType: "QueryDictItemList2",
        model: function () { return 1001; },
        success: function (data) {
            if (data && data.length > 0) {
                $("#formidstate").combobox({ valueField: 'ITEMVALUE', textField: 'ITEMNAME' });
                $("#formidstate").combobox('loadData', data);

            }
        }
    });
}
function linkattach(v, row, index) {
    var _url = downloadurl('feedback', row.FEEDBACK_ATTACHURL, row.FEEDBACK_ATTACHNAME);
    return '<span><input id="attach_name" type="hidden" value="' + row.FEEDBACK_ATTACHNAME + '"/><input id="attach_url" type="hidden" value="' + row.FEEDBACK_ATTACHURL + '"/><a href = "' + _url + '">' + row.FEEDBACK_ATTACHNAME + '</a></span>';
}